<?php
/**
 * Created by PhpStorm.
 * User: J.H
 * Date: 2018/7/8
 * Time: 13:58
 */

namespace lib\aliYun\market;


class NidCard extends BaseApi implements iApi
{
    private $api = 'http://naidcard.market.alicloudapi.com/nidCard';

    private $status = [
        '01' => '实名认证通过',
        '02' => '实名认证不通过',
        '202' => '无法验证',
        '203' => '异常情况',
        '204' => '姓名格式不正确',
        '205' => '身份证格式不正确'
    ];

    public function __construct(array $configs)
    {
        parent::__construct($configs);
        $this->api_url = $this->api;
    }

    public function setParams(array $params)
    {
        $this->params = $params;
    }

    public function getStatus($code)
    {
        if (isset($this->status[$code])) {
            return $this->status[$code];
        }
        return '验证失败';
    }

    /**
     * @return array
     */
    public function execute()
    {
        $result = parent::exec(self::GET, $http_code, $e_code, $e_msg);
        $data = array(
            'status' => false,
            'msg' => '',
            'idCard' => $this->params['idCard'],
            'name' => $this->params['name'],
            'sex' => '',
            'area' => '',
            'province' => '',
            'city' => '',
            'prefecture' => '',
            'birthday' => '',
            'addrCode' => '',
            'lastCode' => ''
        );
        $r_data = $this->parseJson($result);
        $result_data = array_merge($data, $r_data);
        $result_data['msg'] = $this->getStatus($result_data['status']);
        if ('01' === $result_data['status']) {
            $result_data['status'] = true;
        } else {
            $result_data['status'] = false;
        }
        return $result_data;
    }
}